home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-03-09 | 3.1 KB | 107 lines | [TEXT/KAHL] |
- /**********************************************************************************
-
- NOTE: This file won't compile as-is, though each sample has been compiled on its
- own. The code here has been extracted from the article simply for your convenience,
- so you won't have to type it in. Take what you need, and adapt it for your own
- devious purposes.
-
- ***********************************************************************************/
-
-
- //--------------------------------------
- // Changing fonts when using the multiple
- // encodings method in your app.
-
- short fontScript;
- short textRunIndex, textRunCount;
-
- fontScript = Font2Script(myNewFontID);
- for (textRunIndex = 0;
- textRunIndex < textRunCount;
- textRunIndex++) {
- if (textRunStore[textRunIndex].script == fontScript)
- textRunStore[textRunIndex].fontID = myNewFontID;
- else
- SpecialProcessing(&textRunIndex, &textRunCount, myNewFontID);
- }
-
- Boolean FindASCIIRun(unsigned char *textPtr, long textLength,
- long *runLength)
- {
- *runLength = 0;
-
- if (*textPtr < 0x80) {
- // We know that this character is simple ASCII, since values less
- // than 128 can't be the first byte of a two-byte character, and
- // they're shared among all scripts. So, let's block up a run of
- // simple ASCII.
- while (*textPtr++ < 0x80 && textLength-- > 0)
- *runLength++;
- return true; // Run is simple ASCII.
- } else {
- // We know this character is not simple ASCII. It may be two-byte
- // or it may be some character in a non-Roman script. So, let's
- // block up a run of non-simple-ASCII characters.
- while (textLength > 0) {
- if (CharByte(textPtr, 0) == smFirstByte) {
- // Skip over two-byte character.
- textPtr += 2;
- textLength -= 2;
- *runLength += 2;
- } else {
- // Skip over one-byte character.
- textPtr++;
- textLength--;
- *runLength++;
- }
- }
- return false; // Run is NOT simple ASCII.
- }
- }
-
- void SpecialProcessing(short *runIndex, short *runCount,
- short myNewFontID)
- {
- TextRunRecord originalRun, createdRun;
- unsigned char *textPtr;
- long textLength, runLength, runFollow;
- Boolean simpleASCII;
-
- // Retrieve this run and remove it from the run list.
- GetTextRun(*runIndex, &originalRun);
- RemoveTextRun(*runIndex);
-
- // Get the pointer and length of the original text.
- textPtr = originalRun.text;
- textLength = originalRun.count;
-
- // Loop through all of the sub-runs in this run.
- runFollow = *runIndex;
- while (textLength > 0) {
- // Find the length of the sub-run and its type.
- TextFont(originalRun.fontID);
- simpleASCII= FindASCIIRun(textPtr, textLength, &runLength);
-
- // Create the sub-run and duplicate the characters.
- createdRun = originalRun; // Same formats.
- createdRun.text = (unsigned char *)NewPtr(runLength);
- createdRun.length = runLength;
- BlockMove(textPtr, createdRun.text, runLength);
-
- // Roman runs can use the new font.
- if (simpleASCII)
- createdRun.fontID = myNewFontID;
-
- // Add the new sub-run and advance the run index.
- AddTextRun(runFollow++, createdRun);
-
- // Advance over this sub-run and continue looping.
- textPtr += runLength;
- textLength -= runLength;
- }
-
- // Dispose of the original run information.
- DisposeTextRun(originalRun);
- }
-
-